<template>
  <div class="saleAttr">
    <div class="top">
      <img :src="currentSkuInfo.skuInfo.image" alt="" />
      <div class="price">
        <nut-price
          :price="currentSkuInfo.skuInfo.price"
          size="normal"
          position="after"
          symbol="元"
        />
        <div>
          <span
            class="saleAttrValue"
            v-for="(attrValue, attrValueIndex) in currentSkuInfo.attrValueList"
            :key="attrValueIndex"
          >
            {{ attrValue }}
          </span>
        </div>
      </div>
    </div>
    <div
      class="attr"
      v-for="(saleAttr, saleAttrIndex) in spuInfo.saleAttrs"
      :key="saleAttrIndex"
    >
      <span class="title">{{ saleAttr.name }}</span>
      <div class="valueBox">
        <span
          v-for="(attrValue, attrValueIndex) in saleAttr.optionList"
          :key="attrValueIndex"
          :class="[
            {
              active:
                currentSkuInfo.attrOptionSnList[saleAttrIndex] ==
                attrValue.attrOptionSn,
            },
            { disabled: attrValue.disabled },
            'value',
          ]"
          @click="emits('change', attrValue, saleAttrIndex)"
          >{{ attrValue.attrValue }}</span
        >
      </div>
    </div>
    <nut-button type="primary" @click="emits('close')">确定</nut-button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";

// 属性
const props = defineProps({
  currentSkuInfo: {
    type: Object,
  },
  spuInfo: {
    type: Object,
  },
});

// 方法
const emits = defineEmits(["change", "close"]);
</script>

<style lang="less" scoped>
.saleAttr {
  display: flex;
  flex-direction: column;
  padding: 25px 15px 25px 20px;
  :deep(.nut-radio__button--disabled) {
    border: 1px solid #f6f7f9;
    color: #ccc;
  }
  .top {
    display: flex;
    justify-content: flex-start;
    align-items: flex-end;
    margin-bottom: 20px;
    img {
      width: 70px;
      height: 70px;
      border-radius: 5px;
    }
    .price {
      margin-left: 10px;
      display: flex;
      flex-direction: column;
      .nut-price {
        margin-bottom: 5px;
      }
      .saleAttrValue {
        margin-right: 5px;
        font-size: 11px;
        border: 1px solid #efefef;
        padding: 2px 5px;
        border-radius: 5px;
      }
    }
  }
  .attr {
    margin-top: 10px;
    padding: 0px 10px 5px 0px;
    border-radius: 5px;
    background: #fff;
    .title {
      display: block;
      font-weight: bold;
      margin-bottom: 10px;
    }
    .valueBox {
      display: flex;
      flex-wrap: wrap;
      .value {
        display: block;
        margin-right: 12px;
        margin-bottom: 12px;
        font-size: 12px;
        padding: 5px 10px;
        border: 1px solid rgb(242, 242, 242);
        border-radius: 5px;
        background: rgb(242, 242, 242);
      }
      .value.active {
        background: transparent;
        border: 1px solid #fa2c19;
        color: #fa2c19;
      }
      .value.disabled {
        color: #cdcdcd;
        border: 1px solid #efefef;
        background: #efefef;
      }
    }
  }
  .nut-button {
    margin-top: 20px;
    border-radius: 10px;
    height: 45px;
  }
}
</style>